//
//  IGArtWorksCardView.m
//  jingdongfang
//
//  Created by BOE on 2017/8/21.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGArtWorksCardView.h"
#import "IGArtWorksModel.h"

@interface IGArtWorksCardView ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *authorLabel;
@property (nonatomic, strong) UILabel *pushNumLabel;

@end

@implementation IGArtWorksCardView


- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    _imgView = [UIImageView new];
    _imgView.backgroundColor = [UIColor mainRandomColor];
    [self addSubview:_imgView];
    
    _titleLabel = [UILabel new];
    _titleLabel.font = [UIFont font18];
    _titleLabel.textColor = [UIColor c4Color];
    [self addSubview:_titleLabel];
    
    _authorLabel = [UILabel new];
    _authorLabel.font = [UIFont font12];
    _authorLabel.textColor = [UIColor c5Color];
    [self addSubview:_authorLabel];
    
    _pushNumLabel = [UILabel new];
    _pushNumLabel.font = [UIFont font12];
    _pushNumLabel.textColor = [UIColor c5Color];
    _pushNumLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_pushNumLabel];
    
    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(kGAP10);
        make.width.height.mas_equalTo(45);
    }];
    
    [_pushNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_imgView.mas_centerY);
        make.right.mas_equalTo(-kGAP10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(100);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_imgView.mas_right).offset(kGAP15);
        make.top.mas_equalTo(kGAP14);
        make.right.mas_equalTo(_pushNumLabel.mas_left).offset(-kGAP10);
        make.height.mas_equalTo(18);
    }];
    
    [_authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_titleLabel);
        make.top.mas_equalTo(_titleLabel.mas_bottom).offset(kGAP10/2);
        make.right.mas_equalTo(_pushNumLabel.mas_left).offset(-kGAP10);
        make.height.mas_equalTo(23);
    }];
}

- (void)setModel:(IGArtWorksModel *)model {
    _model = model;
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.artPhoto]];
    
    _titleLabel.text = model.artName;
    _authorLabel.text = model.artAuthor;
//    _pushNumLabel.text = [NSString stringWithFormat:@"%@人推送过", model.artPushed];
    _pushNumLabel.text = [NSString stringWithFormat:@"%@ %@", model.artPushed,NSLocalizedString(@"Pushes", nil)];
    [_pushNumLabel sizeToFit];
    [_pushNumLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(_pushNumLabel.size.width);
    }];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
